package cn.software.entity.vo;

import cn.software.entity.Test;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Author gxy
 * @Date 2023/6/5 8:20
 * @PackageName:cn.software.entity.vo
 * @ClassName: TreeVo
 */
public class TreeVo {
    private String name = "考试树状图";
    private TreeViewBranch[] treeViewBranches = new TreeViewBranch[3];

    public TreeVo(List<TestVo> testVoNotStart, List<TestVo> testVoTesting, List<TestVo> testVoEnded) {
        treeViewBranches[0] = new TreeViewBranch("历史考试", testVoEnded);
        treeViewBranches[1] = new TreeViewBranch("可进行考试", testVoTesting);
        treeViewBranches[2] = new TreeViewBranch("未来考试", testVoNotStart);

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public TreeViewBranch[] getTreeViewBranches() {
        return treeViewBranches;
    }

    public void setTreeViewBranches(TreeViewBranch[] treeViewBranches) {
        this.treeViewBranches = treeViewBranches;
    }

    public TreeVo(String name, TreeViewBranch[] treeViewBranches) {
        this.name = name;
        this.treeViewBranches = treeViewBranches;
    }

    public TreeVo() {
    }

    class TreeViewBranch {
        private String testStatus;
        private Root[] roots;

        public TreeViewBranch(String name, List<TestVo> listTestVo) {
            this.testStatus = name;
            if (listTestVo != null) {
                roots = new Root[listTestVo.size()];
                int i = 0;
                for (TestVo testVo : listTestVo) {
                    roots[i++] = new Root(testVo);
                }
            }
        }

        public String getTestStatus() {
            return testStatus;
        }

        public void setTestStatus(String testStatus) {
            this.testStatus = testStatus;
        }

        public Root[] getRoots() {
            return roots;
        }

        public void setRoots(Root[] roots) {
            this.roots = roots;
        }
    }

    class Root {
        private String paperName;
        private String time;

        public Root(TestVo testVo) {
            this.paperName = testVo.getPaperName();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String startTime = formatter.format(testVo.getStartTime());
            String endTime = formatter.format(testVo.getEndTime());
            this.time = startTime + "--" + endTime;
        }

        public String getPaperName() {
            return paperName;
        }

        public void setPaperName(String paperName) {
            this.paperName = paperName;
        }

        public String getTime() {
            return time;
        }

        public void setTime(String time) {
            this.time = time;
        }
    }
}

